package com.jijs.ws.cxfclient.interceptor;

import java.util.List;

import javax.xml.namespace.QName;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.headers.Header;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.phase.Phase;

import com.jijs.ws.cxfclient.bean.User;

public class LicenseUserOutInterceptor extends AbstractSoapInterceptor {

	/**
	 * 说明使用的阶段
	 * 
	 * @param phase
	 */
	public LicenseUserOutInterceptor(String phase) {
		super(phase);
	}
	
	public LicenseUserOutInterceptor(){
		super(Phase.WRITE);
	}
	

	@Override
	public void handleMessage(SoapMessage message) throws Fault {
		try {
			List<Header> headers = message.getHeaders();
			QName qname = new QName("http://ws.jijs.com/","licenseInfo","ns");
			DataBinding binding = new JAXBDataBinding(User.class);
			User user = new User();
			user.setUsername("admin");
			user.setPassword("123456");
			Header header = new Header(qname, user, binding);
			headers.add(header);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
